/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package models;
import java.util.*;
import javax.persistence.*;
import play.data.format.*;
import play.data.validation.*; 

import play.db.jpa.*;
@Entity
public class Persona {
    @Id
    @Constraints.Required
    public Integer numPersona;
    @Constraints.Required
    public String nombres;
    @Constraints.Required
    public String apellidos;
    @Constraints.Required
    public String docIdentidad;
    @Formats.DateTime(pattern="yyyy-MM-dd")
    public Date fechaNacimiento;
    public String direccion;
    
    public static Persona findById(Integer numPersona) {
        return JPA.em().find(Persona.class, numPersona);
    }
    public void update(Integer numPersona) {
        this.numPersona= numPersona;
        JPA.em().merge(this);
    }
    public void save() {
        System.out.println("Grabando nuevo persona...");
        JPA.em().persist(this);
    }
    public void delete() {
        JPA.em().remove(this);
    } 
    
    public static Page page(){
        List<Persona> personas =  JPA.em().createQuery("from Persona").getResultList();
        return new Page(personas);
    }
           
       
    public static class Page{
        private final List<Persona> list;
            
        public Page(List<Persona> data){
                this.list = data;
        }    
        public  List<Persona> getList(){
            return list;
        }               
    }
}